home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / vbasic / setup1.exe / SETUP1.FRM < prev   
Text File  |  1993-07-09  |  15KB  |  412 lines

  1. VERSION 2.00
  2. Begin Form Setup1 
  3.    BackColor       =   &H00400000&
  4.    Caption         =   "Test App Setup"
  5.    ClientHeight    =   2136
  6.    ClientLeft      =   1860
  7.    ClientTop       =   2616
  8.    ClientWidth     =   5640
  9.    ControlBox      =   0   'False
  10.    FillStyle       =   0  'Solid
  11.    FontBold        =   -1  'True
  12.    FontItalic      =   -1  'True
  13.    FontName        =   "MS Sans Serif"
  14.    FontSize        =   24
  15.    FontStrikethru  =   0   'False
  16.    FontUnderline   =   0   'False
  17.    ForeColor       =   &H00000000&
  18.    Height          =   2556
  19.    Icon            =   SETUP1.FRX:0000
  20.    Left            =   1812
  21.    LinkMode        =   1  'Source
  22.    LinkTopic       =   "Form3"
  23.    MaxButton       =   0   'False
  24.    MinButton       =   0   'False
  25.    ScaleHeight     =   178
  26.    ScaleMode       =   3  'Pixel
  27.    ScaleWidth      =   470
  28.    Top             =   2244
  29.    Width           =   5736
  30.    Begin Label Label2 
  31.       BorderStyle     =   1  'Fixed Single
  32.       Caption         =   "To customize this setup program, modify the FORM_LOAD event procedure in this form."
  33.       Height          =   435
  34.       Left            =   15
  35.       TabIndex        =   1
  36.       Top             =   15
  37.       Visible         =   0   'False
  38.       Width           =   5625
  39.    End
  40.    Begin Label Label1 
  41.       BorderStyle     =   1  'Fixed Single
  42.       Caption         =   "This label used for DDE connection to the Program Manager"
  43.       Height          =   390
  44.       Left            =   15
  45.       TabIndex        =   0
  46.       Top             =   525
  47.       Visible         =   0   'False
  48.       Width           =   5610
  49.    End
  50. End
  51.  
  52. Const APPNAME = "Loan Application"
  53. Const APPDIR = "C:\LOAN"    ' The default install directory
  54. Const fDataAccess% = False
  55. Const fODBC% = False
  56. Const fBtrieve% = False
  57. Const fOLE2% = False
  58.  
  59. ' Set the total uncompressed file sizes
  60. ' by adding the sizes of the files
  61. Const WINSYSNEEDED = 40896  ' Files that go into WINDOWS and SYSTEM directory
  62. Const OTHERNEEDED = 12555   ' Files that don't go into the WINDOWS or SYSTEM directory
  63.  
  64. Sub DrawBackground ()
  65.     Setup1.CurrentY = 5
  66.     Setup1.CurrentX = 5
  67.     Setup1.ForeColor = QBColor(15)
  68.     Print APPNAME + " Setup"
  69. End Sub
  70.  
  71. Sub Form_Load ()
  72.     
  73.     '----------
  74.     ' Initialize
  75.     '----------
  76.     dialogCaption$ = APPNAME + " Setup"
  77.     ShowMainForm dialogCaption$
  78.  
  79.     winDrive$ = UCase$(Left$(winDir$, 1))
  80.     winDir$ = UCase$(GetWindowsDir$())
  81.     winSysDir$ = UCase$(GetWindowsSysDir$())
  82.     
  83.     '----------------------------------------------------
  84.     ' Get Window version
  85.     '----------------------------------------------------
  86.     TheVerInfo& = GetVersion()
  87.     WinVer& = TheVerInfo& And &HFFFF&
  88.     If Val(Format$(WinVer& Mod 256) + "." + Format$(WinVer& \ 256)) >= 3.1 Then
  89.         gfWin31% = True
  90.     End If
  91.     
  92.     '----------------------------------------------------
  93.     ' OLE 2.0 requires Win 3.1 or greater
  94.     '----------------------------------------------------
  95.     If fOLE2% And Not gfWin31% Then
  96.         MsgBox "This application requires Windows 3.1 or later"
  97.         GoTo ErrorSetup
  98.     End If
  99.  
  100.     '----------------------------------------------------
  101.     ' SETUP.EXE passes the source drive in a command
  102.     ' argument.  If it is empty,  that means the user
  103.     ' executed this .exe directly.  In that case, show
  104.     ' a dialog to get the desired source directory.
  105.     '----------------------------------------------------
  106.     SourcePath$ = Command$
  107.     If SourcePath$ = "" Then
  108.         title$ = dialogCaption$
  109.         caption1$ = "Please enter the drive or path containing the " + APPNAME + " source files."
  110.         caption2$ = "Install From:"
  111.         defaultDrive$ = "A:"
  112.         defaultText$ = "A:\"
  113.  
  114.         ShowPathDialog title$, caption1$, caption2$, defaultDrive$, defaultText$, SourcePath$, outButton$
  115.  
  116.         If outButton$ = "exit" Then GoTo ErrorSetup
  117.     Else
  118.         If Right$(SourcePath$, 1) <> "\" Then
  119.             SourcePath$ = SourcePath$ + "\"
  120.         End If
  121.     End If
  122.  
  123.  
  124.     '--------------------
  125.     ' Get Destination Path
  126.     '--------------------
  127.     title$ = dialogCaption$
  128.     caption1$ = "If you want to install the test application in a different directory and/or drive, type the name of the directory."
  129.     caption2$ = "Install To:"
  130.     defaultDrive$ = "C:"
  131.     defaultText$ = APPDIR
  132.  
  133.     ShowPathDialog title$, caption1$, caption2$, defaultDrive$, defaultText$, destPath$, outButton$
  134.  
  135.     If outButton$ = "exit" Then GoTo ErrorSetup
  136.     
  137.     '-----------------------------------------
  138.     ' Dim disk space variables as Long Integers
  139.     '-----------------------------------------
  140.     Dim winSpaceFree As Long
  141.     Dim sourceSpaceFree As Long
  142.     Dim destSpaceFree As Long
  143.     Dim totalNeeded As Long
  144.  
  145.     '---------------------------------------------------------
  146.     ' If the Windows \SYSTEM directory is a subdirectory
  147.     ' of the Windows directory, the proper place for
  148.     ' installation of .VBXs and shared .DLLs is the
  149.     ' Windows \SYSTEM directory.
  150.     '
  151.     ' If the Windows \SYSTEM directory is *not* a subdirectory
  152.     ' of the Windows directory, then the user is running a
  153.     ' shared version of Windows, and the proper place for
  154.     ' installation of .VBXs and shared .DLLs is the
  155.     ' Windows directory.
  156.     '---------------------------------------------------------
  157.     If InStr(winSysDir$, winDir$) = 0 Then
  158.         winSysDir$ = winDir$
  159.     End If
  160.  
  161.     
  162.     '---------------------------------
  163.     ' Get Drive Letters of directories
  164.     '---------------------------------
  165.     destDrive$ = UCase$(Left$(destPath$, 1))
  166.     sourceDrive$ = UCase$(Left$(SourcePath$, 1))
  167.  
  168.     '---------------------------------
  169.     ' Compute free disk space variables
  170.     '---------------------------------
  171.     winSpaceFree = GetDiskSpaceFree(winDrive$)
  172.     destSpaceFree = GetDiskSpaceFree(destDrive$)
  173.     
  174.     '-----------------------------------------
  175.     ' Check for enough disk space.
  176.     '
  177.     ' Some components are being installed into the
  178.     ' Windows\SYSTEM directory.
  179.     '
  180.     ' So if the main destination path is on a
  181.     ' different drive than the drive with
  182.     ' the Windows \SYSTEM directory, we have to
  183.     ' check both drives.
  184.     '
  185.     ' An example of this is when the user is installing
  186.     ' the main product to drive D:, but the Windows
  187.     ' directory is on drive c:
  188.     ' -----------------------------------------
  189.     totalNeeded = WINSYSNEEDED + OTHERNEEDED
  190.     
  191.     If winDrive$ = destDrive$ Then
  192.         If destSpaceFree < totalNeeded Then
  193.             MsgBox "There is not enough disk space on drive " + destDrive$ + ":   An estimated" + Str$(totalNeeded - destSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  194.             GoTo ErrorSetup
  195.         End If
  196.     Else
  197.         If winSpaceFree < WINSYSNEEDED Then
  198.             MsgBox "There is not enough disk space on drive " + winDrive$ + ":  An estimated" + Str$(WINSYSNEEDED - winSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  199.             GoTo ErrorSetup
  200.         End If
  201.         If destSpaceFree < OTHERNEEDED Then
  202.             MsgBox "There is not enough disk space on drive " + destDrive$ + ":  An estimated" + Str$(OTHERNEEDED - destSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  203.             GoTo ErrorSetup
  204.         End If
  205.         
  206.     End If
  207.  
  208.     '----------------------------
  209.     ' Create destination directory
  210.     '----------------------------
  211.     If Not CreatePath(destPath$) Then GoTo ErrorSetup
  212.     
  213.  
  214.     '-----------------------------------------------------------
  215.     ' Show Status Dialog -- This stays up while copying files
  216.     ' It is required by the CopyFile routine
  217.     '-----------------------------------------------------------
  218.     ShowStatusDialog dialogCaption$, totalNeeded
  219.     
  220.     
  221.     '-----------
  222.     ' Copy Files
  223.     '-----------
  224.  
  225.     ' Test to see if loan.exe is on the disk, if not then you know the user
  226.     ' did not insert the first disk
  227.     If Not PromptForNextDisk(1, SourcePath$ + "loan.ex_") Then GoTo ErrorSetup
  228.     
  229.     ' Install loan.exe and grid.vbx in the destPath$
  230.     If Not CopyFile(SourcePath$, destPath$, "loan.ex_", "loan.exe") Then GoTo ErrorSetup
  231.     If Not CopyFile(SourcePath$, winSysDir$, "grid.vb_", "grid.vbx") Then GoTo ErrorSetup
  232.  
  233.     ' If you have more than one distribution disk, call PromptForNextDisk after
  234.     ' you have installed all the files from the previous disk. This line tests to
  235.     ' see if foo.da_ is on disk 2. If not, you know the user has not inserted disk 2.
  236.     ' The call to PromptForNextDisk is commented out, since loan.exe can be installed
  237.     ' from a single distribution disk.
  238.     
  239.     ' If Not PromptForNextDisk(2, SourcePath$ + "foo.da_") Then GoTo ErrorSetup
  240.     ' If Not CopyFile(SourcePath$, destPath$, "foo.da_", "foo.dat", 0) Then GoTo ErrorSetup
  241.  
  242.     '--------------------------------------------------
  243.     ' File Copying is over, so unload the status dialog
  244.     '--------------------------------------------------
  245.     Unload StatusDlg
  246.  
  247.     '-----------------------------------------------------------
  248.     ' Show static message while working on DDE to Program Manager
  249.     '-----------------------------------------------------------
  250.     ShowStaticMessageDialog dialogCaption$, "Creating Program Manager Icon..."
  251.  
  252.  
  253.     '--------------------------------------
  254.     ' Create program manager group and icon
  255.     '--------------------------------------
  256.     CreateProgManGroup Setup1, "My Loan Application", "LOAN.GRP"
  257.     CreateProgManItem Setup1, destPath$ + "LOAN.EXE", "My Loan Application"
  258.  
  259.     '-------------------------------------------------
  260.     ' Since SETUP.EXE copies your setup program to the Windows
  261.     ' directory, it is possible for your user to
  262.     ' execute this program directly.
  263.     '
  264.     ' As a usability feature, you may wish to insert code
  265.     ' here to install a program manager icon that executes
  266.     ' your setup program in the windows drive.  This
  267.     ' allows th user to re-run setup at a later time to
  268.     ' install options that were not installed the first
  269.     ' time.
  270.     '-------------------------------------------------
  271.  
  272.     '-------------------
  273.     ' Hide Static Message
  274.     '-------------------
  275.     MessageDlg.Hide
  276.     
  277.  
  278.     '--------------------------------------------------------------
  279.     ' If OLE2.DLL already exists, then ignore the OLE 2 flag.
  280.     ' Otherwise, if we are installing an application that uses
  281.     ' OLE 2.0, we need to register the OLE 2 DLL's via REGEDIT.EXE.
  282.     '
  283.     ' Do not copy OLE dlls unless you check the versions and assure
  284.     ' that the versions you plan to install postdate the ones on
  285.     ' the users machine.
  286.     '
  287.     '
  288.     ' The data access engine and OLE 2.0 need to have SHARE.EXE
  289.     ' loaded. Check AUTOEXEC.BAT and add if needed.  NOTE: If
  290.     ' running Window For WorkGroup, then do not add SHARE.  WFW
  291.     ' use its own sharing mechanism, VSHARE.386.
  292.     '----------------------------------------------------------
  293.     If fDataAccess% Or fOLE2% And Not FileExists(winSysDir$ + "\" + "OLE2.DLL") Then
  294.         ret$ = Space$(255)
  295.         x% = GetPrivateProfileString("BOOT", "NETWORK.DRV", "", ret$, Len(ret$), "SYSTEM.INI")
  296.         If x% Then ret$ = Left(ret$, x%)
  297.         If InStr(1, UCase$(ret$), "WFWNET.DRV") = 0 Then
  298.             AddShareIfNeeded winSysDir$, "SHARE.EXE"
  299.         End If
  300.     End If
  301.  
  302.     '----------------------------
  303.     ' Need to register OLE 2.0 dlls
  304.     '----------------------------
  305.     If fOLE2% And Not FileExists(winSysDir$ + "\" + "OLE2.DLL") Then
  306.         x% = Shell("regedit /s ole2.reg")
  307.     End If
  308.  
  309.     '-------------------------------------------------------
  310.     ' Do not change this if statement.  Used by Setup Wizard
  311.     '-------------------------------------------------------
  312.     If fODBC% Then
  313.         CreateProgManItem Setup1, destPath$ + "ODBCADM.EXE", "ODBC Administrator"
  314.         MsgBox "Before you can run a Visual Basic ODBC application using the SQL Server driver, you must first update the ODBC catalog of stored procedures.  These procedures are provided in the INSTCAT.SQL file.  Typically, the system administrator for SQL Server should install these procedures, using the SQL Server ISQL utility."
  315.     End If
  316.  
  317.     '-------------------------------------------------------
  318.     ' Do not change this if statement.  Used by Setup Wizard
  319.     '-------------------------------------------------------
  320.     If fBtrieve% Then
  321.         ' See notes in Appendix C
  322.         retstr$ = String$(255, 32)
  323.         x% = GetPrivateProfileString%("BTRIEVE", "OPTIONS", "1", retstr$, Len(retstr$), "WIN.INI")
  324.         If x% <= 1 Then
  325.             x% = WritePrivateProfileString%("BTRIEVE", "OPTIONS", "/m:64 /p:4096 /b:16 /f:20 /l:40 /n:12 /t:" + destPath$ + "BTRIEVE.TRN", "WIN.INI")
  326.         End If
  327.     End If
  328.  
  329.     '------------------
  330.     ' Show Final message
  331.     '------------------
  332.     MsgBox APPNAME + " Installation is Complete!", 48, dialogCaption$
  333.    
  334. ExitSetup:
  335.     Setup1.Hide
  336.     RestoreProgMan         'Show the program manager
  337.     End
  338.     Exit Sub
  339.  
  340. ErrorSetup:
  341.     MsgBox APPNAME + " is not properly installed.  Please re-run setup at a later time to install the Test Application properly.", 48, dialogCaption$
  342.     ChDrive winDrive$   ' Set back to hard disk
  343.     ChDir Left$(winDir$, Len(winDir$) - 1)
  344.     End
  345.     Exit Sub
  346.     
  347. End Sub
  348.  
  349. Sub Form_Paint ()
  350.     DrawBackground
  351. End Sub
  352.  
  353. '---------------------------------------------------------------
  354. ' Sets the form's caption, Paints 3-D Background Text, Shows Form
  355. '---------------------------------------------------------------
  356. Sub ShowMainForm (Caption$)
  357.     Screen.MousePointer = 11
  358.     Setup1.Caption = Caption$
  359.     Setup1.Move 0, 0, Screen.Width, Screen.Height * .85
  360.     Setup1.Show
  361.     Setup1.Refresh
  362.  
  363.     Setup1.ScaleMode = 2
  364.     Setup1.FontSize = 24
  365.     Setup1.FontBold = True
  366.     Setup1.FontItalic = True
  367.     
  368.     DrawBackground
  369. End Sub
  370.  
  371. Sub ShowPathDialog (title$, caption1$, caption2$, defaultDrive$, defaultText$, SourcePath$, outButton$)
  372.         Screen.MousePointer = 11
  373.         Load PathDlg
  374.         PathDlg.Caption = title$
  375.         PathDlg.Label1.Caption = caption1$
  376.         PathDlg.Label2.Caption = caption2$
  377.         PathDlg.inDrive.Tag = defaultDrive$
  378.         PathDlg.Text1.Text = defaultText$
  379.         PathDlg.Text1.SelStart = 0
  380.         PathDlg.Text1.SelLength = Len(defaultText$)
  381.         CenterForm PathDlg
  382.         Screen.MousePointer = 0
  383.  
  384.         PathDlg.Show 1
  385.         
  386.         SourcePath$ = PathDlg.outPath.Tag
  387.         outButton$ = PathDlg.outButton.Tag
  388.         Unload PathDlg
  389. End Sub
  390.  
  391. Sub ShowStaticMessageDialog (title$, Caption$)
  392.  
  393.     Load MessageDlg
  394.     CenterForm MessageDlg
  395.     MessageDlg.Caption = title$
  396.     MessageDlg.Label.Caption = Caption$
  397.     MessageDlg.Show
  398.     MessageDlg.Refresh
  399.  
  400. End Sub
  401.  
  402. Sub ShowStatusDialog (title$, totalBytes As Long)
  403.  
  404.     Load StatusDlg
  405.     StatusDlg.Caption = title$
  406.     StatusDlg.total.Tag = Str$(totalBytes)
  407.     CenterForm StatusDlg
  408.     StatusDlg.Show
  409.  
  410. End Sub
  411.  
  412.